package com.ruoyi.common.utils;

import java.util.Random;

public class RandomUtils {
    private static final Random random = new Random();
    private static final int MAX_UNICODE = 0x9FA5; // 最大汉字Unicode编码

    /**
     * 随机生成指定长度的汉字组合
     *
     * @param length 要生成的汉字组合长度
     * @return 随机生成的汉字组合
     */
    public static String generateRandomChinese(int length) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < length; i++) {
            sb.append(generateRandomChar());
        }
        return sb.toString();
    }

    /**
     * 随机生成一个汉字字符
     *
     * @return 随机生成的汉字字符
     */
    private static char generateRandomChar() {
        return (char) (0x4E00 + random.nextInt(MAX_UNICODE - 0x4E00 + 1));
    }
}
